home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / MSG Demo 1.4.source Folder / Demo ƒ / Wipes ƒ / Dissolve wipe.c < prev    next >
Text File  |  1994-04-15  |  5KB  |  145 lines

  1. /**********************************************************************\
  2.  
  3. File:        Dissolve wipe.c
  4.  
  5. Purpose:    Graphic effect from offscreen bitmap to main window (on
  6.             screen).  See comments below for more description.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. #include "timing.h"
  26.  
  27. #define CorrectTime 2
  28. #define theWindowWidth (boundsRect.right-boundsRect.left)
  29. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  30.  
  31. pascal short DissolveWipe(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect);
  32. pascal short DissolveBox(GrafPtr, GrafPtr, Rect*, Rect*);
  33.  
  34. /* the actual dissolve wipe splits the screen into 9 blocks, and dissolves
  35. the source onto the destination by blocks in random order.  That way, each
  36. dissolve is faster, and the whole effect is more interesting. */
  37.  
  38. pascal short DissolveWipe(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect)
  39. {
  40.     char            order[9];
  41.     char            ordertemp;
  42.     int                i;
  43.     long            randtemp;
  44.     Rect            source, dest;
  45.     int                resultCode;
  46.     
  47.     for(i = 0; i < 9; i++)
  48.         order[i] = i;
  49.     
  50.     for(i = 8; i >= 0; i--) {
  51.         randtemp = (((long)Random() + 32767) * (i + 1)) / 65535;
  52.         ordertemp = order[randtemp];
  53.         order[randtemp] = order[i];
  54.         order[i] = ordertemp;
  55.     }
  56.     
  57.     for(i = 0; i < 9; i++) {
  58.         source.top = (order[i] / 3) * (theWindowHeight / 3);
  59.         source.left = (order[i] % 3) * (theWindowWidth / 3);
  60.         source.bottom = (((order[i] / 3) + 1) * theWindowHeight) / 3;
  61.         source.right = (((order[i] % 3) + 1) * theWindowWidth) / 3;
  62.         OffsetRect(&source, boundsRect.left, boundsRect.top);
  63.         
  64.         resultCode=DissolveBox(sourceGrafPtr, destGrafPtr, &source, &source);
  65.         if (resultCode!=0)
  66.             return resultCode;    /* error, stop & return error code */
  67.     }
  68.     
  69.     return 0;
  70. }
  71.  
  72. pascal short DissolveBox(GrafPtr newImage, GrafPtr destGrafPtr, Rect *source, Rect *dest)
  73. {
  74.     long        offRowBytes, sizeOfOff;
  75.     Ptr            myBits;
  76.     Rect        bRect;
  77.     GrafPort    myGrafPort;
  78.     GrafPtr        myGrafPtr;
  79.     RgnHandle    oldClipRgn;
  80.     int            i, j;
  81.     Pattern        thePattern;
  82.     char        order[16];
  83.     long        randtemp;
  84.     char        ordertemp;
  85.     
  86.     /* the dissolve effect works by creating a random set of patterns which sum
  87.     (OR) to a black pattern.  We make another offscreen bitmap and fill it with
  88.     the pattern at each stage, and use it as a mask for the bitcopy.  Here, we
  89.     create the offscreen bitmap. */
  90.     
  91.     SetPort(newImage);
  92.     bRect = *source;
  93.     myGrafPtr = &myGrafPort;
  94.     OpenPort(myGrafPtr);
  95.     offRowBytes = (((source->right - source->left) + 15) >> 4) << 1;
  96.     sizeOfOff = (long)(source->bottom - source->top) * offRowBytes;
  97.     OffsetRect(&bRect, -bRect.left, -bRect.top);
  98.     myBits = NewPtr(sizeOfOff);
  99.     if(myBits == 0L)
  100.         return -1;        /* memory error */
  101.     myGrafPort.portBits.baseAddr = myBits;
  102.     myGrafPort.portBits.rowBytes = offRowBytes;
  103.     myGrafPort.portBits.bounds = bRect;
  104.     myGrafPort.portRect = bRect;
  105.     oldClipRgn = myGrafPort.clipRgn;
  106.     myGrafPort.clipRgn = destGrafPtr->visRgn;
  107.     
  108.     for(i = 0; i < 16; i++)
  109.         order[i] = i;
  110.     
  111.     /* this randomly shuffles the order in which the pattern bits will appear */
  112.     for(i = 15; i >= 0; i--) {
  113.         randtemp = (((long)Random() + 32767) * (i + 1)) / 65535;
  114.         ordertemp = order[randtemp];
  115.         order[randtemp] = order[i];
  116.         order[i] = ordertemp;
  117.     }
  118.     
  119.     for(i = 0; i < 16; i++)
  120.     {
  121.         StartTiming();
  122.         SetPort(myGrafPtr);
  123.         
  124.         for(j = 0; j < 8; j++) thePattern[j] = 0;
  125.         thePattern[order[i] >> 2] = 1 << (order[i] & 0x03);
  126.         thePattern[order[i] >> 2] |= 16 << (order[i] & 0x03);
  127.         thePattern[(order[i] >> 2) + 4] = 1 << (order[i] & 0x03);
  128.         thePattern[(order[i] >> 2) + 4] |= 16 << (order[i] & 0x03);
  129.         
  130.         FillRect(&bRect, &thePattern);
  131.         
  132.         SetPort(destGrafPtr);
  133.         
  134.         CopyMask(&(newImage->portBits), &(myGrafPtr->portBits),
  135.                 &(destGrafPtr->portBits), source, &bRect, dest);
  136.         TimeCorrection(CorrectTime);
  137.     }
  138.     
  139.     myGrafPort.clipRgn = oldClipRgn;
  140.     ClosePort(myGrafPtr);
  141.     DisposPtr(myBits);
  142.     
  143.     return 0;
  144. }
  145.